package com.tanhua.manage.controller;

import com.tanhua.manage.service.PublishInfoService;
import com.tanhua.manage.vo.PageResult;
import com.tanhua.manage.vo.PublishDetailsVo;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("manage/messages")
public class PublishInfoController {


    @Autowired
    private PublishInfoService publishInfoService;

    /**
     *    查询圈子列表   翻页
     * @param pageSize
     * @param page
     * @param sortProrerties
     * @param sortOrder
     * @param publishId
     * @param startDate
     * @param endDate
     * @param userId
     * @param state
     * @return
     */
    @GetMapping
    public ResponseEntity<PageResult> queryPublishList(
            @RequestParam("pagesize") Integer pageSize,
            @RequestParam Integer page,
            @RequestParam("sortProp") String sortProrerties,
            @RequestParam("sortOrder") String sortOrder,
            @RequestParam("id") ObjectId publishId,
            @RequestParam("sd") String startDate,
            @RequestParam("ed") String endDate,
            @RequestParam("uid") Integer userId,
            @RequestParam("state") Integer state) {

        try {
            PageResult pageResult = this.publishInfoService.queryPublishList(
                    page, pageSize, sortProrerties,
                    sortOrder, publishId, userId,
                    startDate, endDate);

            return ResponseEntity.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     *    根据id查询该圈子信息    圈子详情
     * @param publishId
     * @return
     */
    @GetMapping("/{id}")

    public ResponseEntity<PublishDetailsVo> queryPublishInfoById(
            @PathVariable("id") String publishId) {

        try {
            PublishDetailsVo publishDetailsVo = this.publishInfoService.queryPublishDetails(publishId);
            return ResponseEntity.ok(publishDetailsVo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     *    置顶该圈子   二次点击则取反操作
     * @param publishId
     * @return
     */
    @PostMapping("/{id}/top")
    public ResponseEntity<PageResult> topPublishById(
            @PathVariable("id") String publishId
    ) {

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     *    取消置顶该圈子
     * @param publishId
     * @return
     */
    @PostMapping("/{id}/untop")
    public ResponseEntity<PageResult> untopPublishById(
            @PathVariable("id") String publishId
    ) {

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     *   撤销用户的圈子审核操作
     *
     * @return
     */
    @PostMapping("/revocation")

    public ResponseEntity<PageResult> revokeHandle() {

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }


    /**
     * 通过用户的圈子发布
     * @return
     */
    @PostMapping("/pass")

    public ResponseEntity<PageResult> passPublish() {



        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }


    /**
     *   拒绝用户的圈子发布
     * @return
     */
    @PostMapping("/reject")

    public ResponseEntity<PageResult> rejectPublish() {



        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }
}
